# 封装登录，退出方法
# 分析登录方法的参数：需要几个参数，分别代表什么
# 参数就是driver对象
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time


def denlu(driver):
    driver.find_element(By.LINK_TEXT,"登陆").click()
    driver.find_element(By.ID, "username").send_keys("dabai")
    driver.find_element(By.ID, "password").send_keys("1213314")
    driver.find_element(By.LINK_TEXT, '登     陆').click()
    time.sleep(5)

def tuichu(driver):
    # driver.find_element(By.CLASS_NAME,"cur").click()
    # driver.find_element(By.LINK_TEXT,"退出登录").click()
    element1=driver.find_element(By.XPATH,'//*[@id="top-userbar"]/a')
    ActionChains(driver).move_to_element(element1).perform()
    driver.find_element(By.LINK_TEXT,"退出").click()
    time.sleep(5)

def houtaidenlu(driver):
    # driver.find_element(By.ID,"username").send_keys("student1")
    driver.find_element(By.ID, "username").send_keys("student1")
    driver.find_element(By.ID, "password").send_keys("1234567890")
    # driver.find_element(By.ID, "password").send_keys("1234567890")
    driver.find_element(By.LINK_TEXT, '登 陆').click()
    time.sleep(5)

def houtaituichu(driver):
    # driver.find_element(By.CLASS_NAME,"cur").click()
    # driver.find_element(By.LINK_TEXT,"退出登录").click()
    # element1=driver.find_element(By.XPATH,'//*[@id="top-userbar"]/a')
    # ActionChains(driver).move_to_element(element1).perform()
    driver.find_element(By.LINK_TEXT,"退出登录").click()
    time.sleep(5)
def quitbrower(driver):
    driver.quit()
if __name__ == '__main__':
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(10)
    #driver.get("http://39.101.167.251/qftest/")
    driver.get("http://localhost/verydows-master/index.php?m=backend&c=main&a=index")
    houtaidenlu(driver)
    houtaituichu(driver)
    quitbrower(driver)
    # quitbrower(driver)

